package com.wanmait.houlang.service.impl;

import com.github.pagehelper.PageInfo;
import com.wanmait.houlang.mapper.EpikHighMapper;
import com.wanmait.houlang.pojo.EpikHigh;
import com.wanmait.houlang.service.EpikHighService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Service
public class EpikHighServiceImpl implements EpikHighService {
    @Resource
    private EpikHighMapper epikHighMapper;
    @Override
    public void insert(EpikHigh object) {

    }

    @Override
    public void delete(Integer id) {

    }

    @Override
    public void delete(String ids) {

    }

    @Override
    public void update(EpikHigh object) {

    }

    @Override
    public EpikHigh findById(Integer id) {
        return null;
    }

    @Override
    public List<EpikHigh> findAll() {
        return null;
    }

    @Override
    public PageInfo<EpikHigh> findAll(int pageNum, int pageSize, EpikHigh object) {
        return null;
    }


    @Override
    public EpikHigh findEpikHighByScore(String score) {
        EpikHigh epikHighByScore = epikHighMapper.findEpikHighByScore(score);
        return epikHighByScore;
    }

    @Override
    public Integer findPrecedenceBySubjectCodeAndScore(String score, String subjectCodes) {
        //根据成绩获取到一分一段的一整行数据
        EpikHigh epikHigh = this.findEpikHighByScore(score);
        HashMap<String, Integer> scores = new HashMap<>();

        Integer precedence=0;
        scores.put("all",epikHigh.getAll());
        scores.put("phy",epikHigh.getPhy());
        scores.put("che",epikHigh.getChe());
        scores.put("bio",epikHigh.getBio());
        scores.put("ide",epikHigh.getIde());
        scores.put("his",epikHigh.getHis());
        scores.put("geo",epikHigh.getGeo());
        if(subjectCodes!=""){
            //将科目代码表切割到一个数组中
            String[] subCodes = subjectCodes.split(",");
            for (String code:subCodes){
                for(String key:scores.keySet()){
                    if(code.equals(key)){
                        if(precedence!=0&&precedence>=scores.get(key)&&scores.get(key)!=null){
                            precedence=scores.get(key);
                        }
                    }
                }
            }
            if (precedence==0){
                precedence=scores.get("all");
            }
        }
        else{
            precedence=scores.get("all");
        }
        return precedence;
    }


}
